package D12_6z.IO_空参构造_调用get_set方法_3;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        List<Cat> list = new ArrayList<>();
        File file = new File("src/Y2019/M12_/D12_6z/IO_空参构造_调用get_set方法_3/CatData.txt");
        List<String> str = FileUtils.readLines(file);
        for (int i = 0; i < str.size(); i++) {
            Class<?> aClass = Class.forName(str.get(i).split(" ")[0]);
            Method setName = aClass.getDeclaredMethod("setName", String.class);
            setName.setAccessible(true);
            Object o = aClass.newInstance();
            setName.invoke(o,str.get(i).split(" ")[1].split("=")[1].split("’")[1]);
            Method getName = aClass.getDeclaredMethod("getName");
            getName.setAccessible(true);
            System.out.println(getName.invoke(o,null));
            list.add((Cat) o);
        }
    }
}
